#include <e32def.h>
#include <eikenv.h>
#include "HttpConnectionEngine.h"
CHttpConnectionEngine* CHttpConnectionEngine::iConnectionEngine = NULL;

CHttpConnectionEngine::CHttpConnectionEngine()
{
    iSession = new RHTTPSession();
    iSession->OpenL();
    this->iRfs = CEikonEnv::Static()->FsSession();
}
CHttpConnectionEngine::~CHttpConnectionEngine()
{
    if (iSession)
    {
        iSession->Close();
        delete iSession;
    }
}
CHttpConnectionEngine* CHttpConnectionEngine::GetInstance()
{
    if (!iConnectionEngine)
    {
        iConnectionEngine = new CHttpConnectionEngine();
    }
    return iConnectionEngine;
}

void CHttpConnectionEngine::Destroy()
{
    if (iConnectionEngine)
    {
        delete iConnectionEngine;
        iConnectionEngine = NULL;
    }
}

CHttpConnection* CHttpConnectionEngine::HttpRequest( const TDesC8 &aUri, TInt aMethod,
        const TDesC8 &aData, const TDesC &aFileName,
        MHttpRevObserver *aObserver)
{
    CHttpConnection *connection=new CHttpConnection(iRfs,aFileName);
    connection->HttpRequest(iSession,aUri,aMethod,aData,aObserver);
    return connection;
}

void Cancel(CHttpConnection *connection)
{
    if(connection)
    {
        connection->Cancel();
    }
}

